/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package com.lxk.event.oms.enums;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.utils.StreamUtils;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 订单枚举
 *
 * @author heyi
 * 2024/8/20
 */
public interface OrderEnums {

    @AllArgsConstructor
    @Getter
    enum NeedStock {
        YES(0, "需要"),
        NOT(1, "不需要"),
        ;

        private static final Map<Integer, NeedStock> map = CollUtil.toList(NeedStock.values()).stream().collect(Collectors.toMap(NeedStock::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static NeedStock getByCode(Integer code) {
            return map.get(code);
        }
    }


    /**
     * 提货方式  0=快递物流, 1=商家配送 2=用户自提
     */
    @AllArgsConstructor
    @Getter
    enum DeliveryType {
        KD(0, "快递物流"),
        PS(1, "商家配送"),
        ZT(2, "用户自提"),
        ;

        private static final Map<Integer, DeliveryType> map = CollUtil.toList(DeliveryType.values()).stream().collect(Collectors.toMap(DeliveryType::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static DeliveryType getByCode(Integer code) {
            return map.get(code);
        }
    }

    @AllArgsConstructor
    @Getter
    enum PayType {
        WX_JSAPI("WX_JSAPI", "微信公众号支付或者小程序支付"),
        WX_APP("WX_APP", "微信APP支付"),
        WX_MWEB("WX_MWEB", "H5支付"),
        ALI_APP("ALI_APP", "支付宝APP"),
        ALI_MWEB("ALI_MWEB", "支付宝手机快捷支付"),
        YU("YU", "余额支付"),
        PONIT("POINT", "积分支付");
        /**
         * 三方支付
         */
        public static final List<String> WX_PAY = CollUtil.newArrayList(WX_JSAPI, WX_APP, WX_MWEB).stream().map(PayType::getCode).toList();
        public static final List<String> ALI_PAY = CollUtil.newArrayList(ALI_APP, ALI_MWEB).stream().map(PayType::getCode).toList();
        public static final List<String> THIRD_PAY = CollUtil.newArrayList(WX_PAY, ALI_PAY).stream().flatMap(Collection::stream).toList();
        private static final Map<String, PayType> map = CollUtil.toList(PayType.values()).stream().collect(Collectors.toMap(PayType::getCode, v -> v));
        private final String code;
        private final String name;

        public static Boolean containCode(String code) {
            return map.containsKey(code);
        }

        public static PayType getByCode(String code) {
            return map.get(code);
        }
    }

    /**
     * 售后状态  0=未售后, 1=部分售后,2=全部售后
     */
    @AllArgsConstructor
    @Getter
    public enum SaleAfterStatus {
        NOT(0, "未售后"),
        PART(1, "部分售后"),
        ALL(2, "全部售后");


        private static final Map<Integer, SaleAfterStatus> map = CollUtil.toList(SaleAfterStatus.values()).stream().collect(Collectors.toMap(SaleAfterStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static SaleAfterStatus getByCode(Integer code) {
            return map.get(code);
        }
    }

    /**
     * 售后状态（0=未售后 1=售后中 2=已售后）
     */
    @AllArgsConstructor
    @Getter
    public enum PostStatus {
        INIT_0(0, "未售后"),
        ING_1(1, "售后中"),
        SUCCESS_2(2, "已售后"),
        PART_3(3, "部分售后");


        private static final Map<Integer, PostStatus> map = CollUtil.toList(PostStatus.values()).stream().collect(Collectors.toMap(PostStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static PostStatus getByCode(Integer code) {
            return map.get(code);
        }
    }

    /**
     * 退款状态（0=未退款 1=部分退款 2=全部退款）
     */
    @AllArgsConstructor
    @Getter
    enum RefundStatus {
        NOT(0, ""),
        PART(1, ""),
        ALL(2, "全部退款"),
        ;

        private static final Map<Integer, RefundStatus> map = CollUtil.toList(RefundStatus.values()).stream().collect(Collectors.toMap(RefundStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static RefundStatus getByCode(Integer code) {
            return map.get(code);
        }
    }

    /**
     * 0无需分账 1未分账 2待分账 3分账中 4分账失败 5分账完成
     */
    @AllArgsConstructor
    @Getter
    enum DivideStatus {
        INIT(0, ""),
        NOT(1, ""),
        WAIT(2, ""),
        ING(3, ""),
        FAIL(4, ""),
        SUCCESS(5, "");

        private static final Map<Integer, DivideStatus> map = CollUtil.toList(DivideStatus.values()).stream().collect(Collectors.toMap(DivideStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static DivideStatus getByCode(Integer code) {
            return map.get(code);
        }
    }

    @AllArgsConstructor
    @Getter
    enum PayStatus {
        NOT(0, "未支付"),
        YES(1, "已支付"),

        ;

        private static final Map<Integer, PayStatus> map = CollUtil.toList(PayStatus.values()).stream().collect(Collectors.toMap(PayStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static PayStatus getByCode(Integer code) {
            return map.get(code);
        }
    }

    /**
     * 0=创建等待支付   100=支付中 200=支付成功  300=待发货待配送  400=确认收货/配送完成 500=用户取消订单  501=超时未支付取消 502=商家取消订单
     */
    @AllArgsConstructor
    @Getter
    enum OrderStatus {
        CREATE_0(0, "创建等待支付"),
        PAYING_100(100, "支付中"),
        PAY_SUCCESS_200(200, "支付成功"),
        SEND_300(300, "待发货待配送"),
        WAIT_CONFIRM_350(350, "待收货/使用"),
        WAIT_EVALUATION_370(370, "待评价"),
        CONFIRM_400(400, "订单完成"),
        CANCEL_500(500, "用户取消订单"),
        CANCEL_501(501, "超时未支付取消"),
        CANCEL_502(502, "商家取消订单"),
        ;

        /**
         * 订单取消类型
         */
        public final static List<Integer> CANCEL_CODE = CollUtil.newArrayList(CANCEL_500, CANCEL_501, CANCEL_502).stream().map(OrderStatus::getCode).toList();
        private static final Map<Integer, OrderStatus> map = CollUtil.toList(OrderStatus.values()).stream().collect(Collectors.toMap(OrderStatus::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static OrderStatus getByCode(Integer code) {
            return map.get(code);
        }

        public static List<OrderStatus> toListByCodeList(List<Integer> code) {
            return code.stream().map(OrderStatus::getByCode).filter(ObjectUtil::isNotNull).toList();
        }
    }

    /**
     * 订单类型
     */
    @AllArgsConstructor
    @Getter
    enum OrderType {
        ORDER_NORMAL(0, "普通订单"),
        ORDER_POINT(1, "积分订单"),
        YU_RECHARGE(100, "余额充值订单"), BZ_RECHARGE(101, "保证金充值订单"), YJ_RECHARGE(102, "押金充值订单"),
        ;

        public final static List<OrderType> NEED_STOCK = CollUtil.newArrayList(ORDER_NORMAL, ORDER_POINT);
        public final static List<OrderType> VIRTUAL_TYPE = CollUtil.newArrayList(YU_RECHARGE, BZ_RECHARGE, YJ_RECHARGE);
        public final static List<Integer> VIRTUAL_TYPE_CODE = StreamUtils.toList(VIRTUAL_TYPE, OrderType::getCode);
        private static final Map<Integer, OrderType> map = CollUtil.toList(OrderType.values()).stream().collect(Collectors.toMap(OrderType::getCode, v -> v));
        private final Integer code;
        private final String name;

        public static Boolean containCode(Integer code) {
            return map.containsKey(code);
        }

        public static OrderType getByCode(Integer code) {
            return map.get(code);
        }
    }
}
